package org.xjtu.weteam.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import org.xjtu.weteam.model.domain.Team;

import java.util.List;

/**
 * @author Kevin
 */

@Mapper
public interface TeamMapper extends BaseMapper<Team> {
    //void insertTeam(Team team, Integer userID);
    @Insert("INSERT INTO Team (team_name, description, image_path) VALUES (#{teamName}, #{description}, #{imagePath})")
    @Options(useGeneratedKeys = true, keyProperty = "teamId")
    int insertTeam(Team team);
    @Select("select * from team where team.team_id = #{teamid} and team.is_enabled = 1")
    Team selectById(@Param("teamid") Integer teamid);

    // 使用提供的user_id和team_id插入user_team关系
    @Insert("INSERT INTO user_team (user_id, team_id, role) VALUES (#{userId}, #{teamId}, #{role})")
    int insertUserTeam(@Param("userId") Integer userId, @Param("teamId") Integer teamId, @Param("role") String role);

    @Select("select count(*) from user_team where user_id = #{userId} and team_id = #{teamId}")
    int checkIfJoin(@Param("userId") Integer userId, @Param("teamId") Integer teamId);
    List<Team> selectJoinTeams(@Param("userid") Integer userid);
    @Delete("update team set is_enabled=0 where team_id = #{teamId}")
    void deleteTeam(@Param("teamId") Integer teamId);
}
